<?php
/**
 * Created by cmb_weixin.master.
 * File: Goods.php
 * User: xuewl
 * Date: 2017/12/11
 * Time: 23:55
 */

namespace app\api\controller\v1\goods;
use app\api\controller\v1\Init;
class Goods extends Init
{
    protected $model;

    public function _initialize() {
        parent::_initialize();
        $this->model = model('goods/goods', 'service');
    }


    /**
     * 获取商品列表
     * @return \think\Response
     */
    public function items() {
        extract($this->params, true);
        $maps = ['status' => 1];
        if(isset($type)) {
            $maps['type'] = (int) $type;
        }
        if(isset($keyword) && !empty($keyword)) {
            $maps['title'] = ['like', "%".$keyword."%"];
        }

        if(isset($point)) {
            $maps['point'] = ['between', $point];
        }



        $result = $this->model->lists($maps, $this->limit, $this->page, $order);
        return $this->response(lang('Operation completed'), $result);
    }

    public function item() {
        $result = $this->model->where(['id' => (int) $this->params['id']])->find();
        if(!$result) {
            return $this->response('商品不存在', [], -20002);
        }
        return $this->response(lang('Operation completed'), $result);
    }
}
